package com.kgc.cgprovider.controller;

import com.kgc.basic.util.ResponseMsg;
import com.kgc.cgapi.service.CGApi;
import com.kgc.cgprovider.service.CGServ;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CGController implements CGApi {

    Logger logger = LoggerFactory.getLogger(CGController.class);

    @Autowired
    private CGServ cgServ;

    @Override
    public String getCode(String table) {
        logger.info("getCode Table:" + table);
        String code = cgServ.getCode(table);
        logger.info("getCode Code:" + code + "table:" + table);
        return code;
    }

    @Override
    public ResponseMsg del(String table, String code) {
        logger.info("del table{},code:{} ", table, code);
        ResponseMsg responseMsg = cgServ.del(table, code);
        logger.info("del table{},code:{} respons{}", table, code,responseMsg);
        return responseMsg;

    }

    @Override
    public ResponseMsg closeOrder(String table, String code) {
        ResponseMsg responseMsg = new ResponseMsg();
        boolean flag = cgServ.closeOrder(table, code);
        logger.info("closeOrder table{},code:{} flag:{}", table, code, flag);
        if (flag) {
            responseMsg.setCode(200);
        }else {
            responseMsg.setCode(500);
        }
        return responseMsg;
    }
}
